package inet.app.controller.parser;

import inet.app.model.object.KqGiai_Item;

import java.util.ArrayList;


public class Parser_Kq_Cau {

	private String NAME = "XS_CAU_RESP";
	private ArrayList<String> list = new ArrayList<String>();
	private ArrayList<KqGiai_Item> list_giai = new ArrayList<KqGiai_Item>();
	public Parser_Kq_Cau() {
	}
	public ArrayList<String> getList(String json) {
		String[] data = json.split("\\|\\|\r\n");
		System.out.println("DATA SIZE " + data.length);
		String[] item_first = data[0].split("\\|");
		System.out.println("DATA OOOOOOOOOOOOOOOOOO +" + data[0]);
		String name = item_first[0];
		
		String status = item_first[1];
		if (status.equals("0") && name.equals(NAME)) {
			int i = 0;
			String item;
			String kqgiai[] ;
			String last_update, code,date,dacbiet= null, giai1 = null, giai2= null,giai3= null,giai4 = null,giai5= null,giai6= null,giai7= null,giai8= null;
			for (i = 0; i < data.length; i++) {
				kqgiai = data[i].split("\\|");
				last_update= kqgiai[2];
				code = kqgiai[3];
				String[] temp;
				temp= kqgiai[4].split(" ");
				date = temp[0];
				for (int j =5; j < kqgiai.length; j++) {
					
					if(kqgiai[j].substring(0,1).equals("0")){ System.out.println("GIAI O " + kqgiai[j]);dacbiet = kqgiai[j];}
					else if(kqgiai[j].substring(0,1).equals("1")) giai1 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("2")) giai2 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("3")) giai3 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("4")) giai4 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("5")) giai5 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("6")) giai6 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("7")) giai7 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("8")) {if (kqgiai[j].equals("8:")==true) {
						giai8= kqgiai[j]+ "null";
					}else giai8 = kqgiai[j];}
				}
				
				item = kqgiai[0]+"|"+kqgiai[1] +"|"+kqgiai[2] +"|"+kqgiai[3]+"|"+kqgiai[4]  +"|"+dacbiet +"|"+giai1+"|"+giai2+"|"+giai3+"|"+giai4+"|"+giai5+"|"+giai6+"|"+giai7+"|"+giai8;
				
				list.add(item);
			}
			return list;
		} else
			return null;
	}
	
public ArrayList<KqGiai_Item> getList_date(String json) {
		
		String[] data = json.split("\\|\\|\r\n");
		System.out.println("DATA SIZE " + data.length);
		String[] item_first = data[0].split("\\|");
		
		String name = item_first[0];
		
		String status = item_first[1];
		if (status.equals("0") && name.equals(NAME)) {
			int i = 0;
			KqGiai_Item item;
			String kqgiai[] ;
			String last_update, code,date,dacbiet= null, giai1 = null, giai2= null,giai3= null,giai4 = null,giai5= null,giai6= null,giai7= null,giai8= null;
			for (i = 0; i < data.length; i++) {
				kqgiai = data[i].split("\\|");
				last_update= kqgiai[2];
				code = kqgiai[3];
				String[] temp;
				temp= kqgiai[4].split(" ");
//				date = kqgiai[4];
				date = temp[0];
				
				for (int j = 5; j < kqgiai.length; j++) {
					if(kqgiai[j].substring(0,1).equals("0")) dacbiet = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("1")) giai1 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("2")) giai2 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("3")) giai3 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("4")) giai4 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("5")) giai5 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("6")) giai6 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("7")) giai7 = kqgiai[j];
					else giai8 = kqgiai[j];
				}
				
				item = new KqGiai_Item(last_update,code, date, dacbiet, giai1, giai2, giai3, giai4, giai5, giai6, giai7,giai8);
				list_giai.add(item);
			}
			return list_giai;
		} else
			return null;
	}

public String getString(String json) {
		String _result = null;
		String[] data = json.split("\\|\\|\r\n");
		System.out.println("DATA SIZE " + data.length);
		String[] item_first = data[0].split("\\|");
		
		String name = item_first[0];
		
		String status = item_first[1];
		if (status.equals("0") && name.equals(NAME)) {
			return json;
		} else
			return null;
	}

	public String getList(String json,String matinh) {
	String _result = null;
	String[] data = json.split("\\|\\|\r\n");
	System.out.println("DATA SIZE " + data.length);
	String[] item_first = data[0].split("\\|");
	
	String name = item_first[0];
	
	String status = item_first[1];
	if (status.equals("0") && name.equals(NAME)) {
		int i = 0;
		KqGiai_Item item;
		String kqgiai[] ;
		String last_update,code,date,dacbiet= null, giai1 = null, giai2= null,giai3= null,giai4 = null,giai5= null,giai6= null,giai7= null,giai8= null;
		for (i = 0; i < data.length; i++) {
			kqgiai = data[i].split("\\|");
			last_update= kqgiai[2];
			code = kqgiai[3];
				kqgiai = data[i].split("\\|");
				for (int j = 5; j < kqgiai.length; j++) {
					if(kqgiai[j].substring(0,1).equals("0")) dacbiet = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("1")) giai1 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("2")) giai2 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("3")) giai3 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("4")) giai4 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("5")) giai5 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("6")) giai6 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("7")) giai7 = kqgiai[j];
					else if(kqgiai[j].substring(0,1).equals("8")) {if (kqgiai[j].equals("8:")==true) {
						giai8= kqgiai[j]+ "null";
					}else giai8 = kqgiai[j];}
				}
				_result = kqgiai[0]+"|"+kqgiai[1] +"|"+kqgiai[2] +"|"+kqgiai[3] +"|"+kqgiai[4] +"|"+dacbiet +"|"+giai1+"|"+giai2+"|"+giai3+"|"+giai4+"|"+giai5+"|"+giai6+"|"+giai7+"|"+giai8;
				
				return _result;
		}
		return _result;
	} else
		return null;
}


}
